package com.harvest.scientific.ladder.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.google.android.material.shape.MaterialShapeDrawable;
import com.harvest.scientific.ladder.R;

import androidx.annotation.NonNull;

import static com.harvest.scientific.ladder.ext.CommonHelper.dp2px;
import static com.harvest.scientific.ladder.ext.CommonHelper.getScreenWidth;

public class PictureSelDialog extends Dialog {

    private FrameLayout rightCloseContainer;
    private TextView tvAlbum;
    private TextView tvTake;


    private int dialogWidth = 0, dialogHeight = 0;


    public PictureSelDialog(@NonNull Context context) {
        super(context, R.style.dialogStyle);
        //统一弹窗默认边距40px
        setDialogWidth((int) (getScreenWidth() - 2 * dp2px(40f)));
    }


    @SuppressLint("WrongConstant")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_picture_sel);

        WindowManager.LayoutParams Params = getWindow().getAttributes();
        if (dialogWidth != 0) {
            Params.width = dialogWidth;
        }
        if (dialogHeight != 0) {
            Params.height = dialogHeight;
        }
        getWindow().setAttributes(Params);

        rightCloseContainer = findViewById(R.id.top_close_container);
        tvTake = findViewById(R.id.tvTake);
        tvAlbum = findViewById(R.id.tvAlbum);

        rightCloseContainer.setOnClickListener(view -> dismiss());

        tvTake.setOnClickListener(view -> {
            if (takeClickListener != null) {
                takeClickListener.onClick(view);
            }
            dismiss();
        });

        tvAlbum.setOnClickListener(view -> {
            if (albumClickListener != null) {
                albumClickListener.onClick(view);
            }
            dismiss();
        });

    }

    public void setDialogWidth(int dialogWidth) {
        this.dialogWidth = dialogWidth;
    }

    public void setDialogHeight(int dialogHeight) {
        this.dialogHeight = dialogHeight;
    }

    public PictureSelDialog setAlbumClick(View.OnClickListener listener) {
        this.albumClickListener = listener;
        return this;
    }

    public PictureSelDialog setTakeClick(View.OnClickListener listener) {
        this.takeClickListener = listener;
        return this;
    }


    private View.OnClickListener takeClickListener;
    private View.OnClickListener albumClickListener;

}
